sudo cat 追加文件报权限错误

1
sudo cat hosts.patch > /etc/hosts

系统提示Permission Denied

因为该命令会分成两步执行:

1
sudo cat hosts.patch #有sudo

1
> /etc/hosts #并没有sudo权限

解决:

1
2
3
4
5
sudo sh -c "cat hosts.patch > /etc/hosts"

# 或者:

echo "cat hosts.patch > /etc/hosts" | sudo sh

http://nigelzeng.iteye.com/blog/1696678

坚持原创技术分享,您的支持将鼓励我继续创作!